<?php

namespace common\models\business;

use Yii;

/**
 * This is the model class for table "business_vaccine".
 *
 * @property string $id
 * @property integer $pigid
 * @property string $remark
 * @property integer $date
 * @property integer $createtime
 */
class BusinessVaccine extends \yii\db\ActiveRecord
{

    public $no;


    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '疫苗',      //用于修改了什么的显示
        'mainfield' => 'id',      //主要的显示标题的字段
        'picturefield' => [],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>[],      //不需要记录的字段
    ];


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'business_vaccine';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['pigid','vaccineid'], 'required'],
            [['pigid', 'createtime','vaccineid','date'], 'integer'],
            [['remark'], 'string', 'max' => 255],
            [['vaccinename'], 'string', 'max' => 20],
//            ['date','safe']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'pigid' => '仔猪',
            'remark' => '备注',
//            'date' => '疫苗时间',
            'createtime' => '疫苗时间',
            'vaccinename' => '疫苗名称',
            'vaccineid' => '疫苗'
        ];
    }


    public function beforeSave($insert)
    {
        $this->date = strtotime($this->date);
        $this->createtime = time();
        return parent::beforeSave($insert); // TODO: Change the autogenerated stub
    }



    public function getPig()
    {
        return $this->hasOne(BusinessPig::className(),['id'=>'pigid']);
    }


    /**
     *
     * 获取疫苗时间
     */
    public function getVaccinedate()
    {
        return $this->hasOne(BusinessVaccineSet::className(),['id'=>'vaccineid']);
    }




}
